# 使用 .NET SDK 作为构建环境
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

# 复制项目文件
COPY ["tafei-thingsapi.csproj", "./"]
RUN dotnet restore

# 复制源代码
COPY . .

# 构建应用程序
RUN dotnet build "tafei-thingsapi.csproj" -c Release -o /app/build

# 发布应用程序
RUN dotnet publish "tafei-thingsapi.csproj" -c Release -o /app/publish

# 使用 .NET Runtime 作为运行环境
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app

# 设置时区为上海
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 从构建阶段复制发布文件
COPY --from=build /app/publish .

# 暴露端口
EXPOSE 80
EXPOSE 443

# 设置环境变量
ENV ASPNETCORE_URLS=http://+:80
ENV ASPNETCORE_ENVIRONMENT=Production

# 启动应用程序
ENTRYPOINT ["dotnet", "tafei-thingsapi.dll"] 